<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="../vue.js"></script>
  </head>
  <body>
    <!-- 
    命名插槽 具名插槽 有名字 
    匿名插槽       没有名字
  -->
    <div id="app">
      <ul>
        <li @click="toggle(item)" v-for="item,index in arr" :key="index">
          {{item}}
        </li>
      </ul>
      <hr />
      <contain :type="sel"></contain>
    </div>

    <template id="contain">
      <div>{{ type }}</div>
    </template>

    <script>
      /*
    wacth 
    */
      //  var a = 1;
      //  var a;
      //  a = 1;
      Vue.component("contain", {
        template: "#contain",
        props: ["type"],
        watch: {
          // type(newV, oldV) {
          //   console.log(newV,oldV)
          //   setTimeout(() => {
          //     console.log('请求数据',newV)
          //   },300)
          // }
          type: {
            immediate: true,
            handler(newV) {
              setTimeout(() => {
                console.log("请求数据", newV);
              }, 300);
            },
          },
        },
      });

      new Vue({
        el: "#app",
        data: {
          arr: ["爱情", "恐怖", "动作"],
          sel: "爱情",
        },
        methods: {
          toggle(type) {
            this.sel = type;
          },
        },
      });
    </script>
  </body>
</html>
